﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="FeedMap"
    targetNamespace="http://schemas.microsoft.com/sqlcommunity/2008/3/RSSData/FeedMap.xsd"
    elementFormDefault="qualified"
    xmlns="http://schemas.microsoft.com/sqlcommunity/2008/3/RSSData/FeedMap.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
	<!-- Note: Not all features in the schema have been implemented yet.  See the release notes for details.  -->
	<!-- The root element which contains all the connections to provide RSS feeds for.  This allows one RSS server to service multiple 
	     databases or use different connection strings or table sets for the same database depending on user experience and security requirements.  -->
	<xs:element name="FeedMap">
		<xs:complexType>
			<xs:sequence>
				<!-- What database to provide the syndication feed for and how to authenticate access -->
				<xs:element name="Connection">
					<xs:complexType>
						<xs:sequence>
							<!-- Optional ancillary tables used to provide additional information for the syndication feed titles and descriptions -->
							<xs:element name ="ReferenceTable" minOccurs="0" maxOccurs="unbounded">
								<xs:complexType>
									<xs:sequence>
										<!-- The primary key or primary keys for the table -->
										<xs:element name="ID" type="ColumnSequence" minOccurs="1"/>
										<!-- Which columns should be accessible, and also provide the ability to remap the names in case of ambiguity 
										     or for readability or security requirements.  -->
										<xs:element name="DataView" type="ColumnSequence" minOccurs="1" maxOccurs="unbounded" />
									</xs:sequence>
									<!-- The name of the reference table.  This should be the schema qualified name of the physical table.  -->
									<xs:attribute name="Name" type="xs:string" use="required" />
								</xs:complexType>
							</xs:element>
							<!-- The primary table which will be used to generate a syndication feed.  Change Tracking must be enabled for
							     this table.  -->
							<xs:element name="Table" minOccurs="1" maxOccurs="unbounded">
								<xs:complexType>
									<xs:sequence>
										<!-- The primary key or primary keys of the table -->
										<xs:element name="ID" type="ColumnSequence" minOccurs="0" maxOccurs="unbounded" />
										
										<!-- What to use as the title of the syndication feed item.  The TitleMode attribute controls how the Title 
										     element is interpreted.  -->
										<xs:element name="Title" type="xs:string" minOccurs="1" maxOccurs="1" />
										
										<!-- What to use as the description of the syndication feed item.  The DescriptionMode attribute controls 
										     how the Description element is interpreted.  -->
										<xs:element name="Description" type="xs:string" minOccurs="1" maxOccurs="1" />
										
										<!-- Optionally determines which column should be used to supply the date for the syndication feed item.  
										     If not specified the time at which the change is noticed will be used. It is good to supply the 
											 actual date column if possible.  -->
										<xs:element name="DateColumn" type="xs:string" minOccurs="0" maxOccurs="1" />
										
										<!-- Optionally determines where data comes from.  The DataViewSourceMode attribute controls how the
										     DataViewSource element is interpreted.  If no DataViewSource is specified the name of 
											 the Table element is used. -->
										<xs:element name="DataViewSource" type="xs:string" minOccurs="0" maxOccurs="1" />
										
										<!-- Optionally determines the columns used to display the changed data when the link in the syndication
										     item is clicked.  The DataDisplayMode attribute controls whether this information is used, and 
											 how it is used.  -->
										<xs:element name="DataView" type="ColumnSequence" minOccurs="0" maxOccurs="1" />
										
										<!-- Optional ancillary tables to join to this one in order to generate syndication feed item 
										     titles and descriptions.  If specified here, these tables must be configured using the ReferenceTable 
											 element above.  -->
										<xs:element name="ReferenceTable" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
									</xs:sequence>
									<!-- The name of the table used to generate the change syndication feed -->
									<xs:attribute name="Name" type="xs:string" use="required" />
									
									<!-- A value or values to use in order to filter the results sent to the syndication feed.  The ChangeFilterMode
									     attribute controls how these values are interpreted.  -->
									<xs:attribute name="ChangeFilter" type="xs:string" />
									
									<!-- Controls how ChangeFilter is interpreted.  If ChangeFilterMode is "Top" then ChangeFilter should be 
									     a positive integer.  The syndication feed will get the top n rows rendered as a syndication item per row.
										 if ChangeFilterMode is "TimeInterval" then ChangeFilter should be a time interval of the form [[hh:]mm:]ss where 
										 the square brackets indicate optional items and should not be typed literally, and hh is two digits of optional 
										 hours, mm is optional minutes, and ss is mandatory seconds.    The syndication
										 feed will get only get items that lie within the time interval between now and now minus the specified time interval.
										 -->
									<xs:attribute name="ChangeFilterMode" type="ChangeFilterModeType" />
									
									<!-- Determines how to interpret the Title element.  
									     If TitleMode is "Format" then Title should be
									     a string which contains text to be output to the syndication feed item title.  The text is used 
										 literally except items within curly brackets.  Primarily the text within the curly bracket is the name of
										 either a physical column or a DisplayName (logical column) from a DataView in either the table
										 being tracked or in a table joined to the table being tracked (a ReferenceTable).  Punctuation and 
										 other non-constiutents within the curly backets are displayed as literals along with the data retrieved 
										 from the physical or logical column if the contents of the column in the changed row (or related row) 
										 are not null. 
										 
										 If TitleMode is "Function" then Title is the name of a scalar user defined function to be invoked.  The function
										 should return a string (nvarchar) which will be used as the title of syndication feed item.
										 -->
									<xs:attribute name="TitleMode" type="DescriptionModeType" />
									
									<!-- Determines how to interpret the Description element.
									     If DescriptionMode is "Format" then Description should be
									     a string which contains text to be output to the syndication feed item title.  The text is used 
										 literally except items within curly brackets.  Primarily the text within the curly bracket is the name of
										 either a physical column or a DisplayName (logical column) from a DataView in either the table
										 being tracked or in a table joined to the table being tracked (a ReferenceTable).  Punctuation and 
										 other non-constiutents within the curly backets are displayed as literals along with the data retrieved 
										 from the physical or logical column if the contents of the column in the changed row (or related row) 
										 are not null. 
										 
										 If DescriptionMode is "Function" then Description is the name of a scalar user defined function to be invoked.  
										 The function should return a string (nvarchar) which will be used as the description of syndication feed item.
										 
										 This is analagous to TitleMode.  See above.-->
									<xs:attribute name="DescriptionMode" type="DescriptionModeType" />
									
									<!-- When present and subject to the DataDisplayMode setting, DataViewSourceMode determines how 
									     data is gathered to present to the user if the user clicks on the link associated with a syndication feed item.
										 If DataViewSourceMode is "Table" then the DataViewSource element must be the name of a table to be
										 displayed.  Exactly how the table will be rendered is determined by the DataDisplayMode attribute
										 and the DataView element. If DataViewSourceMode is "Function" then the DataViewSource element must
										 be the name of a table-valued function.  The function is invoked to get the table to be rendered
										 subject to the setting of the DataDisplayMode attribute.-->
									<xs:attribute name="DataViewSourceMode" type="DataViewSourceModeType" />
									
									<!-- Determines what happens when the link associated with a syndication feed item is clicked.  
									     If DataDisplayMode is "Report" then the ReportBaseURL attribute below must be specified.  The link
										 associated with the feed will be the concatenation of the ReportBaseURL plus query parameters for each
										 primary key specified using the ID element.  This enables integration with Reporting Services and also
										 any other web data display technology.  The DataViewSourceMode (if specified) is ignored.
										 
										 If DataDisplayMode is "HTML" then the link associated with the feed will generate a simple HTML table.  The
										 DataViewSourceMode attribute determines how the data is gathered (either from a table or table valued function), 
										 and the DataView element determines which columns are displayed.  The DisplayName attribute of
										 the Column element controls the title of the column.  If no DisplayName is specified, the Name of the Column
										 is used.
										 
										 If DataDisplayMode is "XML" then the link associated with the feed will generate XML.  The XML
										 generated will have a root element named "Row".  Within this element the element names will be determined
										 by the DataView columns.  If the DisplayName of the Column element is specified in the DataView, then 
										 the DisplayName is used as the element name within the Row element, otherwise the Name attribute is used
										 to name the element.  The value of the element is determined by the contents of the column.  For example
										 the XML might look something like 
										 <Row> <ProductReviewID>42</ProductReviewID> <ProductName>Tricycle</ProductName> </Row>
										 The source of the data (table or function) is determined by the DataViewSourceMode attribute above.
										 -->
									<xs:attribute name="DataDisplayMode" type="DataDisplayModeType" default="Report" />
									
									<!-- When DataViewSourceMode is "Report" then the ReportBaseURL attribute specifies the first part of 
									     the URL to use when the user clicks on the syndication feed item link.  The rest of the URL will
										 be a concatenation of the primary keys as query parameters on the URL.  -->
									<xs:attribute name="ReportBaseURL" type="xs:anyURI" />
									
									<!-- The FeedTitle attribute contains literal text which is used as the title for the overall syndication feed. -->
									<xs:attribute name="FeedTitle" type="xs:string" use="required"/>
									
									<!-- The FeedDescription attribute contains literal text which is used as the overall description 
									     of the syndication feed.-->
									<xs:attribute name="FeedDescription" type="xs:string" use="required"/>
									
									<!-- The FeedAlternateUrl attribute contains literal text which is used as a general link for the syndication feed. -->
									<xs:attribute name="FeedAlternateUrl" type="xs:anyURI" use="required"/>
								</xs:complexType>
							</xs:element>
						</xs:sequence>
						
						<!-- The Name attribute is the logical name of the connection.  It must be specified as a query parameter for the syndication feed. -->
						<xs:attribute name="Name" type="xs:string" use="required" />
						
						<!-- How long to continue to transmit the currently cached syndication feed before checking the database for updates.  -->
						<xs:attribute name="CacheDuration" type="xs:int" />
						
						<!-- Physical server, database, and authentication information. -->
						<xs:attribute name="ConnectionString" type="xs:string" use="required" />
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	
	<!-- This type represents an ordered list of columns.  -->
	<xs:complexType name="ColumnSequence">
		<xs:sequence>
			<xs:element name="Column" minOccurs="1" maxOccurs="unbounded">
				<xs:complexType>
					<!-- The primary or physical name of the column-->
					<xs:attribute name="Name" type="xs:string" use="required" />
					<!-- The friendly name of the column.  Used when outputing the data, and also used to disambiguate identically named columns
					     in format strings. -->
					<xs:attribute name="DisplayName" type="xs:string" />
				</xs:complexType>
			</xs:element>
			<!-- Optional separator to use when concatenating several columns together (for example, to build a single identity 
			string for the syndication feed). -->
			<xs:element name="Separator" type="xs:string" minOccurs="0" maxOccurs="1" />
		</xs:sequence>
	</xs:complexType>
	
	<!-- This type represents a description of what should happen if the link for the syndication feed item is followed. -->
	<xs:simpleType name="DataDisplayModeType">
		<xs:restriction base="xs:string">
			<!-- Generate a simple HTML table of data results.  Controlled by several attributes in the Table element-->
			<xs:enumeration value="HTML" />
			
			<!-- Generate XML for programatic consumption-->
			<xs:enumeration value="XML" />
			
			<!-- Use Reporting Services (or some other web site for describing the changed data) to display the change. -->
			<xs:enumeration value="Report" />
		</xs:restriction>			
	</xs:simpleType>
	
	<!-- This type represents a description of how to get the data for display after a syndication feed item link has been clicked 
	     for some DataDisplayModes -->
	<xs:simpleType name="DataViewSourceModeType">
		<xs:restriction base="xs:string">
			<!-- Get the data directly from a table -->
			<xs:enumeration value="Table" />
			<!-- Invoke a table-valued function and use the data from it-->
			<xs:enumeration value="Function" />
		</xs:restriction>
	</xs:simpleType>
	
	<!-- This type represents a description of how to get the data for a title or description for a syndication feed item -->
	<xs:simpleType name="DescriptionModeType">
		<xs:restriction base="xs:string">
			<!-- Use something like a format string. The text is used 
				 literally except items within curly brackets.  Primarily the text within the curly bracket is the name of
				 either a physical column or a DisplayName (logical column) from a DataView in either the table
				 being tracked or in a table joined to the table being tracked (a ReferenceTable).  Punctuation and
				 other non-constiutents within the curly backets are displayed as literals along with the data retrieved
				 from the physical or logical column if the contents of the column in the changed row (or related row)
				 are not null. -->
			<xs:enumeration value="Format" />
			
			<!-- Invoke a scalar function which returns the title or description of a syndication feed item. -->
			<xs:enumeration value="Function" />
		</xs:restriction>
	</xs:simpleType>
	
	<!-- This type is used to express determine how results from the database are filtered prior to transmission to the syndication feed.  -->
	<xs:simpleType name="ChangeFilterModeType">
		<xs:restriction base="xs:string">
			<!-- Indicates that the n most recent changes should be presented to the user via the syndication feed.  The ChangeFilter 
			     attribute controls the value of n. -->
			<xs:enumeration value="Top" />
			
			<!-- Indicates that a specific date/time range should be present to the user via the syndication feed. The ChangeFilter attribute
			     is used to specify the start and end dates and times. -->
			<xs:enumeration value="TimeInterval" />
		</xs:restriction>
	</xs:simpleType>
	
</xs:schema>
